const { DataTypes } = require('sequelize');
const { nanoid } = require('nanoid');
const sequelize = require('../config/database');

const Inventory = sequelize.define('Inventory', {
  id: {
    type: DataTypes.STRING,
    primaryKey: true,
    defaultValue: () => nanoid()
  },
  productCode: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
    comment: '商品编码'
  },
  productName: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '商品名称'
  },
  specification: {
    type: DataTypes.STRING,
    allowNull: true,
    comment: '规格'
  },
  unit: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '单位'
  },
  quantity: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: '库存数量'
  },
  remark: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '备注'
  }
}, {
  timestamps: true,
  paranoid: true,
  tableName: 'inventory'
});

module.exports = Inventory;